"""The bandwidth test for TAPA."""

# Copyright (c) 2024 RapidStream Design Automation, Inc. and contributors.
# All rights reserved. The contributor(s) of this file has/have agreed to the
# RapidStream Contributor License Agreement.

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//bazel:tapa_rules.bzl", "tapa_xo")
load("//bazel:v++_rules.bzl", "vpp_xclbin")

exports_files(
    [
        ".",
        "bandwidth.cpp",
        "bandwidth.h",
        "lfsr.h",
    ],
    visibility = ["//tests/functional:__subpackages__"],
)

sh_test(
    name = "bandwidth",
    size = "medium",
    srcs = ["//bazel:v++_env.sh"],
    args = ["$(location bandwidth-host)"],
    data = [":bandwidth-host"],
    env = {"TAPA_CONCURRENCY": "1"},
)

sh_test(
    name = "bandwidth-xosim",
    size = "enormous",
    timeout = "moderate",
    srcs = ["//bazel:v++_env.sh"],
    args = [
        "$(location bandwidth-host)",
        "--bitstream=$(location bandwidth-xo)",
        "--xosim_executable=$(location //tapa/cosim:tapa-fast-cosim)",
        "1000",
    ],
    data = [
        ":bandwidth-host",
        ":bandwidth-xo",
        "//tapa/cosim:tapa-fast-cosim",
    ],
    tags = [
        "cpu:2",
    ],
)

sh_test(
    name = "bandwidth-cosim",
    size = "enormous",
    timeout = "moderate",
    srcs = ["//bazel:v++_env.sh"],
    args = [
        "$(location bandwidth-host)",
        "--bitstream=$(location bandwidth-hw-emu-xclbin)",
        "1000",
    ],
    data = [
        ":bandwidth-host",
        ":bandwidth-hw-emu-xclbin",
    ],
    tags = [
        "cpu:2",
    ],
)

cc_binary(
    name = "bandwidth-host",
    srcs = glob([
        "*.cpp",
        "*.h",
    ]),
    deps = [
        "//tapa-lib:tapa",
        "@gflags",
        "@vitis_hls//:include",
    ],
)

tapa_xo(
    name = "bandwidth-xo",
    src = "bandwidth.cpp",
    hdrs = glob(["*.h"]),
    include = ["."],
    platform_name = "xilinx_u250_gen3x16_xdma_4_1_202210_1",
    top_name = "Bandwidth",
)

vpp_xclbin(
    name = "bandwidth-hw-emu-xclbin",
    platform_name = "xilinx_u250_gen3x16_xdma_4_1_202210_1",
    target = "hw_emu",
    top_name = "Bandwidth",
    xo = ":bandwidth-xo",
)
